package ipdesk.model.report.seminar.dao;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.ibatis.dao.client.DaoManager;

import ipdesk.model.report.seminar.bean.SeminarInfoBean;

import ecg.dao.DaoService;


public class SeminarInfoDao
{
	private static SeminarInfoDao singleton;
	
	protected SeminarInfoDao(){}
	
	public static SeminarInfoDao getInstance()
	{
		if(singleton == null)
		{
			singleton = new SeminarInfoDao();
		}
		
		return singleton;
	}
	
	
	private DaoManager	manager	= DaoService.getInstance();
	private ISeminarInfo seminarInfo 	= (ISeminarInfo)manager.getDao(ISeminarInfo.class, "ip_desk");
	
	/*
	 * 입력받은 데이터를 DB에 insert 하는 메서드.
	 */
	public int seminarInfoReg(SeminarInfoBean seminarInfoBean) throws Exception
	{
		int lastSeminarSeq = 0;
		
		try{
			// 트랜잭션 시작
			manager.startTransaction();
			
			// 상담정보 insert.
			lastSeminarSeq = seminarInfo.seminarInfoReg(seminarInfoBean);
			
			manager.commitTransaction();
		}finally{
			manager.endTransaction();
		}

		
		return lastSeminarSeq;
	}
	
	public void insertFileData(SeminarInfoBean seminarInfoBean) throws Exception
	{
		try{
			manager.startTransaction();
			
			seminarInfo.insertFileData(seminarInfoBean);
			
			manager.commitTransaction();
		}finally{
			manager.endTransaction();
		}
		
	}
	
	public int getDataTotalCount(SeminarInfoBean seminarInfoBean) throws Exception
	{
		int totalDataCount = seminarInfo.getDataTotalCount(seminarInfoBean);
		
		return totalDataCount;
	}
	
	
	public List<SeminarInfoBean> getPagingDataListForUser(Map map) throws Exception
	{
		
		List<SeminarInfoBean> pageDataList = seminarInfo.getPagingDataListForUser(map);
			
		return pageDataList; 
	}
	
	public SeminarInfoBean getDetailData(int seminarSeq) throws Exception
	{
		SeminarInfoBean seminarInfoBean = seminarInfo.getDetailData(seminarSeq);
		
		seminarInfoBean.setDiscussIssue(seminarInfoBean.getDiscussIssue().replace("<br/>", "\n"));
		//System.out.println(" =---- :: "+seminarInfoBean.getStartDate());
		return seminarInfoBean;
	}
	
	public void delFileData(String fileSeq) throws Exception
	{
		seminarInfo.delFileData(fileSeq);
	}
	
	public void updateDelFileData(String fileSeq) throws Exception
	{
		seminarInfo.updateDelFileData(fileSeq);
	}
	
	public void updateDelPicData(String fileSeq) throws Exception
	{
		seminarInfo.updateDelPicData(fileSeq);
	}
	
	public void delDetailData(int seminarSeq) throws Exception
	{
		seminarInfo.delDetailData(seminarSeq);
	}
	
	public void seminarInfoUpdate(SeminarInfoBean seminarInfoBean) throws Exception
	{
		try{
			manager.startTransaction();
			
			// 2. seminar DB update
			seminarInfo.seminarInfoUpdate(seminarInfoBean);
			
			manager.commitTransaction();
		}finally{
			manager.endTransaction();
		}
	}
	
	public void insertFileData2(SeminarInfoBean seminarInfoBean) throws Exception
	{
		seminarInfo.insertFileData2(seminarInfoBean);
	}
	
	public void updateFileData(SeminarInfoBean seminarInfoBean) throws Exception 
	{
		seminarInfo.updateFileData(seminarInfoBean);
	}
	
	public SeminarInfoBean getFileDetailData(int seminarSeq, String fileCategory) throws Exception
	{
		SeminarInfoBean seminarInfoBean = new SeminarInfoBean();
		seminarInfoBean.setSeminarSeq(seminarSeq);
		seminarInfoBean.setFileCategory(fileCategory);
		
		return seminarInfo.getFileDetailData(seminarInfoBean);
	}
}
